import java.util.ArrayList;
import java.util.Iterator;
import java.util.ListIterator;

public class Demo04 {
    public static void main1(String[] args) {
//        int[] array = new int[9];
        ArrayList<Integer> arrayList = new ArrayList<>();
        arrayList.add(2);
        arrayList.add(7);
        arrayList.add(88);
        arrayList.add(79);
        System.out.println(arrayList);

//        方法二：
        for (int i = 0; i < arrayList.size(); i++) {
            System.out.print(arrayList.get(i) + " ");
        }
        System.out.println();

//        foreach循环
        for (int x :arrayList) {
            System.out.print(x+" ");
        }
        System.out.println();

//        迭代器
        Iterator<Integer> iterator = arrayList.iterator();
        while (iterator.hasNext()){
            System.out.print(iterator.next() + " ");
        }
        System.out.println();

//        从后往前
        ListIterator<Integer> integerListIterator = arrayList.listIterator(arrayList.size());
        while (integerListIterator.hasPrevious()){
            System.out.print(integerListIterator.previous()+" ");
        }
    }

}
